package com.example.teamilkmall.controller;

import com.example.teamilkmall.controller.vo.ResultVO;
import com.example.teamilkmall.entity.Account;
import com.example.teamilkmall.service.AccountService;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author czl
 * @Date 2025-01-07
 */
@RestController
@RequestMapping("/account")
public class AccountController extends BaseController {
    private final AccountService accountService;

    public AccountController(AccountService accountService) {
        this.accountService = accountService;
    }

    @GetMapping("/listAccount")
    public ResultVO<PageInfo<Account>> listAccount(Integer limit, Integer page, String name){
        PageInfo<Account> pageInfo = accountService.listAccount(limit, page, name);
        return success(pageInfo);
    }

    @PostMapping("/updateAccount")
    public ResultVO updateAccount(Account account){
        accountService.updateAccount(account);
        return success();
    }

    @PostMapping("/deloneAccount")
    public ResultVO deloneAccount(Integer id){
        accountService.deloneAccount(id);
        return success();
    }

    @PostMapping("/addAccount")
    public ResultVO addAccount(Account account){
        accountService.addAccount(account);
        return success();
    }

    @PostMapping("/listAccountAll")
    public ResultVO<List<Account>> getAccountList(){
        return success(accountService.listAccountAll());
    }


}
